/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package pe.edu.pucp.dp1.gui.vista;

import Shared.ServProc;
import com.sun.tracing.dtrace.ArgsAttributes;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.Image;
import java.awt.Toolkit;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.awt.event.MouseMotionAdapter;
import java.rmi.Naming;
import javax.imageio.ImageIO;
import javax.swing.BorderFactory;
import javax.swing.JComponent;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.UIManager;
import javax.swing.border.Border;
import pe.edu.pucp.dp1.gui.controlador.GestorGUI;
import pe.edu.pucp.dp1.persistencia.bd.BaseDatos;
//import pe.edu.pucp.dp1.gui.controlador.GestorConexion;
//import pe.edu.pucp.dp1.lectura.controlador.MainLectura;
import pe.edu.pucp.dp1.procesamiento.controlador.GestorInterseccion;

public class Principal extends javax.swing.JFrame {

    public static GestorGUI gestorGUI = GestorGUI.getInstance();
    public static GestorInterseccion gestorInter = GestorInterseccion.getInstance();
    //public static GestorConexion gestorConexion = GestorConexion.getInstance();

    Mapa mapa;
    MiniMapa miniMapa;

    ThreadMap threadMap;
    private Boolean usuarioAdmin = false;

    int nZonasLargo = 0;
    int nZonasAlto = 0;

    public Principal(Boolean isAdmin) {
        initComponents();
        //Ventana centrada
        Dimension dim = Toolkit.getDefaultToolkit().getScreenSize();
        this.setLocation(dim.width / 2 - this.getSize().width / 2, dim.height / 2 - this.getSize().height / 2);

        mapa = new Mapa();
        miniMapa = new MiniMapa();

        threadMap = new ThreadMap(mapa, jScrollPane1);
        threadMap.start();
        //jScrollPane1.setViewportView(mapa);  
        /*jScrollPane1.setHorizontalScrollBarPolicy(
         JScrollPane .HORIZONTAL_SCROLLBAR_ALWAYS);
         jScrollPane1.setVerticalScrollBarPolicy(
         JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);*/

        ActInfoTextual();

        this.usuarioAdmin = isAdmin;
        btnIniSim.setEnabled(true);
        //RMI
        nZonasAlto = gestorInter.getnZonasAlto();
        nZonasLargo = gestorInter.getnZonasLargo();

        System.out.println("De Server RMI - nZonasAlto: " + nZonasAlto);
        System.out.println("De Server RMI - nZonasLargo: " + nZonasLargo);

        if (this.usuarioAdmin) {
            System.out.println("Usuario Admin");
            gestorGUI.IniciarPintaZona();
        } else {
            System.out.println("Usuario Comun");
            gestorGUI.IniciarPintaZona();
            //Deshabilitamos
            btnIniSim.setEnabled(false);
            btnActSim.setEnabled(false);
            menuManten.setEnabled(false);
            menuReportes.setEnabled(false);
        }
        pnlContainerMiniMapa.add(miniMapa);

        ConfigurarMiniMapa();
        //Pintar HotSites en Minimapa
        //ZonasPatronMiniMapa();

    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        pnlMapa = new javax.swing.JPanel();
        jScrollPane1 = new javax.swing.JScrollPane();
        btnMapaDerecha = new javax.swing.JButton();
        btnMapaArriba = new javax.swing.JButton();
        btnMapaIzquierda = new javax.swing.JButton();
        btnMapaAbajo = new javax.swing.JButton();
        lblCoord00 = new javax.swing.JLabel();
        pnlDataActual = new javax.swing.JPanel();
        jLabel2 = new javax.swing.JLabel();
        jLabel1 = new javax.swing.JLabel();
        lblZonaPosX = new javax.swing.JLabel();
        lblZonaPosY = new javax.swing.JLabel();
        txtZonaPosY = new javax.swing.JTextField();
        txtZonaPosX = new javax.swing.JTextField();
        jButton2 = new javax.swing.JButton();
        lblErrorZonaActual = new javax.swing.JLabel();
        pnlSimulacion = new javax.swing.JPanel();
        btnIniSim = new javax.swing.JButton();
        btnActSim = new javax.swing.JButton();
        jButton1 = new javax.swing.JButton();
        pnlControles = new javax.swing.JPanel();
        lblCoordValue = new javax.swing.JLabel();
        lblCoordText = new javax.swing.JLabel();
        pnlContainerMiniMapa = new javax.swing.JPanel();
        pnlVelProm = new javax.swing.JPanel();
        lblVelocidadProm = new javax.swing.JLabel();
        btnActVelProm = new javax.swing.JButton();
        menuMain = new javax.swing.JMenuBar();
        menuArchivo = new javax.swing.JMenu();
        menuManten = new javax.swing.JMenu();
        menuInter = new javax.swing.JMenuItem();
        menuReportes = new javax.swing.JMenu();
        jMenuItem1 = new javax.swing.JMenuItem();
        jMenuItem2 = new javax.swing.JMenuItem();
        jMenuItem3 = new javax.swing.JMenuItem();
        jMenuItem4 = new javax.swing.JMenuItem();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        setResizable(false);
        getContentPane().setLayout(new org.netbeans.lib.awtextra.AbsoluteLayout());

        pnlMapa.setPreferredSize(new java.awt.Dimension(400, 400));
        pnlMapa.setLayout(new org.netbeans.lib.awtextra.AbsoluteLayout());

        jScrollPane1.setBorder(null);
        jScrollPane1.setPreferredSize(new java.awt.Dimension(504, 504));
        pnlMapa.add(jScrollPane1, new org.netbeans.lib.awtextra.AbsoluteConstraints(60, 70, 500, 500));

        btnMapaDerecha.setIcon(new javax.swing.ImageIcon(getClass().getResource("/pe/edu/pucp/dp1/gui/imagenes/right30x30.png"))); // NOI18N
        btnMapaDerecha.setPreferredSize(new java.awt.Dimension(40, 40));
        btnMapaDerecha.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnMapaDerechaActionPerformed(evt);
            }
        });
        pnlMapa.add(btnMapaDerecha, new org.netbeans.lib.awtextra.AbsoluteConstraints(570, 280, -1, -1));

        btnMapaArriba.setIcon(new javax.swing.ImageIcon(getClass().getResource("/pe/edu/pucp/dp1/gui/imagenes/up30x30.png"))); // NOI18N
        btnMapaArriba.setToolTipText("");
        btnMapaArriba.setPreferredSize(new java.awt.Dimension(40, 40));
        btnMapaArriba.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnMapaArribaActionPerformed(evt);
            }
        });
        pnlMapa.add(btnMapaArriba, new org.netbeans.lib.awtextra.AbsoluteConstraints(290, 20, -1, -1));

        btnMapaIzquierda.setIcon(new javax.swing.ImageIcon(getClass().getResource("/pe/edu/pucp/dp1/gui/imagenes/left30x30.png"))); // NOI18N
        btnMapaIzquierda.setPreferredSize(new java.awt.Dimension(40, 40));
        btnMapaIzquierda.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnMapaIzquierdaActionPerformed(evt);
            }
        });
        pnlMapa.add(btnMapaIzquierda, new org.netbeans.lib.awtextra.AbsoluteConstraints(10, 290, -1, -1));

        btnMapaAbajo.setIcon(new javax.swing.ImageIcon(getClass().getResource("/pe/edu/pucp/dp1/gui/imagenes/down30x30.png"))); // NOI18N
        btnMapaAbajo.setPreferredSize(new java.awt.Dimension(40, 40));
        btnMapaAbajo.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnMapaAbajoActionPerformed(evt);
            }
        });
        pnlMapa.add(btnMapaAbajo, new org.netbeans.lib.awtextra.AbsoluteConstraints(290, 580, -1, -1));

        lblCoord00.setText("( , )");
        pnlMapa.add(lblCoord00, new org.netbeans.lib.awtextra.AbsoluteConstraints(20, 570, -1, -1));
        lblCoord00.getAccessibleContext().setAccessibleName("lblCoord00");

        getContentPane().add(pnlMapa, new org.netbeans.lib.awtextra.AbsoluteConstraints(22, 11, 620, 633));

        pnlDataActual.setBorder(javax.swing.BorderFactory.createTitledBorder("Zona Actual"));

        jLabel2.setText("Posición Inicial Eje X:");

        jLabel1.setText("Posición Inicial Eje Y:");

        lblZonaPosX.setText("Ninguna");

        lblZonaPosY.setText("Ninguna");

        jButton2.setText("Ir a Zona");
        jButton2.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton2ActionPerformed(evt);
            }
        });

        lblErrorZonaActual.setForeground(new java.awt.Color(255, 0, 0));

        javax.swing.GroupLayout pnlDataActualLayout = new javax.swing.GroupLayout(pnlDataActual);
        pnlDataActual.setLayout(pnlDataActualLayout);
        pnlDataActualLayout.setHorizontalGroup(
            pnlDataActualLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(pnlDataActualLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(pnlDataActualLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(pnlDataActualLayout.createSequentialGroup()
                        .addComponent(txtZonaPosX, javax.swing.GroupLayout.PREFERRED_SIZE, 51, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(18, 18, 18)
                        .addComponent(txtZonaPosY, javax.swing.GroupLayout.PREFERRED_SIZE, 51, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 51, Short.MAX_VALUE)
                        .addComponent(jButton2))
                    .addGroup(pnlDataActualLayout.createSequentialGroup()
                        .addGroup(pnlDataActualLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(pnlDataActualLayout.createSequentialGroup()
                                .addComponent(jLabel2)
                                .addGap(18, 18, 18)
                                .addComponent(lblZonaPosX, javax.swing.GroupLayout.PREFERRED_SIZE, 50, javax.swing.GroupLayout.PREFERRED_SIZE))
                            .addGroup(pnlDataActualLayout.createSequentialGroup()
                                .addComponent(jLabel1)
                                .addGap(18, 18, 18)
                                .addComponent(lblZonaPosY, javax.swing.GroupLayout.PREFERRED_SIZE, 50, javax.swing.GroupLayout.PREFERRED_SIZE)))
                        .addGap(0, 0, Short.MAX_VALUE)))
                .addContainerGap())
            .addGroup(pnlDataActualLayout.createSequentialGroup()
                .addGap(49, 49, 49)
                .addComponent(lblErrorZonaActual, javax.swing.GroupLayout.PREFERRED_SIZE, 136, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        pnlDataActualLayout.setVerticalGroup(
            pnlDataActualLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(pnlDataActualLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(pnlDataActualLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel2)
                    .addComponent(lblZonaPosX))
                .addGap(24, 24, 24)
                .addGroup(pnlDataActualLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel1)
                    .addComponent(lblZonaPosY))
                .addGap(18, 18, 18)
                .addGroup(pnlDataActualLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(txtZonaPosX, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(txtZonaPosY, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jButton2))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(lblErrorZonaActual, javax.swing.GroupLayout.PREFERRED_SIZE, 21, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap())
        );

        getContentPane().add(pnlDataActual, new org.netbeans.lib.awtextra.AbsoluteConstraints(670, 280, 280, 170));

        pnlSimulacion.setBorder(javax.swing.BorderFactory.createTitledBorder("Simulación"));

        btnIniSim.setText("Iniciar simulación");
        btnIniSim.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnIniSimActionPerformed(evt);
            }
        });

        btnActSim.setText("Actualizar 10min");
        btnActSim.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnActSimActionPerformed(evt);
            }
        });

        jButton1.setText("Leer vehículos");
        jButton1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton1ActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout pnlSimulacionLayout = new javax.swing.GroupLayout(pnlSimulacion);
        pnlSimulacion.setLayout(pnlSimulacionLayout);
        pnlSimulacionLayout.setHorizontalGroup(
            pnlSimulacionLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(pnlSimulacionLayout.createSequentialGroup()
                .addGap(73, 73, 73)
                .addGroup(pnlSimulacionLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addComponent(btnIniSim, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(btnActSim, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(jButton1, javax.swing.GroupLayout.PREFERRED_SIZE, 113, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap(82, Short.MAX_VALUE))
        );
        pnlSimulacionLayout.setVerticalGroup(
            pnlSimulacionLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(pnlSimulacionLayout.createSequentialGroup()
                .addGap(21, 21, 21)
                .addComponent(btnIniSim, javax.swing.GroupLayout.PREFERRED_SIZE, 23, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(18, 18, 18)
                .addComponent(btnActSim)
                .addGap(18, 18, 18)
                .addComponent(jButton1)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        getContentPane().add(pnlSimulacion, new org.netbeans.lib.awtextra.AbsoluteConstraints(670, 30, 280, 170));

        pnlControles.setBorder(javax.swing.BorderFactory.createTitledBorder("Controles"));
        pnlControles.setPreferredSize(new java.awt.Dimension(260, 190));
        pnlControles.setLayout(new org.netbeans.lib.awtextra.AbsoluteLayout());

        lblCoordValue.setText("(0,0)");
        pnlControles.add(lblCoordValue, new org.netbeans.lib.awtextra.AbsoluteConstraints(110, 190, -1, -1));

        lblCoordText.setText("Coordenadas:");
        pnlControles.add(lblCoordText, new org.netbeans.lib.awtextra.AbsoluteConstraints(20, 190, -1, -1));

        pnlContainerMiniMapa.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(153, 51, 0), 2));
        pnlContainerMiniMapa.setPreferredSize(new java.awt.Dimension(244, 164));

        javax.swing.GroupLayout pnlContainerMiniMapaLayout = new javax.swing.GroupLayout(pnlContainerMiniMapa);
        pnlContainerMiniMapa.setLayout(pnlContainerMiniMapaLayout);
        pnlContainerMiniMapaLayout.setHorizontalGroup(
            pnlContainerMiniMapaLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 240, Short.MAX_VALUE)
        );
        pnlContainerMiniMapaLayout.setVerticalGroup(
            pnlContainerMiniMapaLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 160, Short.MAX_VALUE)
        );

        pnlControles.add(pnlContainerMiniMapa, new org.netbeans.lib.awtextra.AbsoluteConstraints(20, 20, -1, -1));

        getContentPane().add(pnlControles, new org.netbeans.lib.awtextra.AbsoluteConstraints(670, 460, 280, 220));

        pnlVelProm.setBorder(javax.swing.BorderFactory.createTitledBorder("Velocidad promedio"));
        pnlVelProm.setLayout(new org.netbeans.lib.awtextra.AbsoluteLayout());

        lblVelocidadProm.setText("0.0");
        pnlVelProm.add(lblVelocidadProm, new org.netbeans.lib.awtextra.AbsoluteConstraints(30, 20, 91, 30));

        btnActVelProm.setText("Actualizar");
        btnActVelProm.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnActVelPromActionPerformed(evt);
            }
        });
        pnlVelProm.add(btnActVelProm, new org.netbeans.lib.awtextra.AbsoluteConstraints(170, 20, -1, -1));

        getContentPane().add(pnlVelProm, new org.netbeans.lib.awtextra.AbsoluteConstraints(670, 210, 280, 60));

        menuArchivo.setText("Archivo");
        menuMain.add(menuArchivo);

        menuManten.setText("Mantenimiento");

        menuInter.setText("Semáforos");
        menuInter.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                menuInterActionPerformed(evt);
            }
        });
        menuManten.add(menuInter);

        menuMain.add(menuManten);

        menuReportes.setText("Reportes");

        jMenuItem1.setText("Zonas optimizadas");
        jMenuItem1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jMenuItem1ActionPerformed(evt);
            }
        });
        menuReportes.add(jMenuItem1);

        jMenuItem2.setText("Zonas congestionadas");
        jMenuItem2.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jMenuItem2ActionPerformed(evt);
            }
        });
        menuReportes.add(jMenuItem2);

        jMenuItem3.setText("Señalizaciones por zona");
        jMenuItem3.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jMenuItem3ActionPerformed(evt);
            }
        });
        menuReportes.add(jMenuItem3);

        jMenuItem4.setText("Carga vehicular por horas");
        jMenuItem4.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jMenuItem4ActionPerformed(evt);
            }
        });
        menuReportes.add(jMenuItem4);

        menuMain.add(menuReportes);

        setJMenuBar(menuMain);

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void btnIniSimActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnIniSimActionPerformed
        //INICIAR SIMULACION POR RMI
        gestorInter.iniSimIntersecciones();

        gestorGUI.IniciarPintaZona();
        btnActSim.setEnabled(true);
    }//GEN-LAST:event_btnIniSimActionPerformed

    private void menuInterActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_menuInterActionPerformed
        MantSemaforo mantSemaforo = new MantSemaforo(this, true);

        mantSemaforo.setVisible(true);
    }//GEN-LAST:event_menuInterActionPerformed

    private void btnMapaAbajoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnMapaAbajoActionPerformed
        int posActX = gestorGUI.getZonaActivaX();
        int posActY = gestorGUI.getZonaActivaY();
        if (posActY > 0) {
            posActY -= 1000;
            gestorGUI.setZonaActivaY(posActY);
            ActInfoTextual();
        } else {
            System.out.println("Se trata de exceder el límite Inferior");
        }
    }//GEN-LAST:event_btnMapaAbajoActionPerformed

    private void btnMapaIzquierdaActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnMapaIzquierdaActionPerformed
        int posActX = gestorGUI.getZonaActivaX();
        int posActY = gestorGUI.getZonaActivaY();
        if (posActX > 0) {
            posActX -= 1000;
            gestorGUI.setZonaActivaX(posActX);
            ActInfoTextual();
        } else {
            System.out.println("Se trata de exceder el límite Izquierdo");
        }
    }//GEN-LAST:event_btnMapaIzquierdaActionPerformed

    private void btnMapaArribaActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnMapaArribaActionPerformed
        int posActX = gestorGUI.getZonaActivaX();
        int posActY = gestorGUI.getZonaActivaY();
        //OBTENER DIMENSIONES DE ZONA POR RMI
        if (posActY < (nZonasAlto - 1) * 1000) {
            posActY += 1000;
            gestorGUI.setZonaActivaY(posActY);
            ActInfoTextual();
        } else {
            System.out.println("Se trata de exceder el límite Superior");
        }
    }//GEN-LAST:event_btnMapaArribaActionPerformed

    private void btnMapaDerechaActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnMapaDerechaActionPerformed
        int posActX = gestorGUI.getZonaActivaX();
        int posActY = gestorGUI.getZonaActivaY();

        if (posActX < (nZonasLargo - 1) * 1000) {
            posActX += 1000;
            gestorGUI.setZonaActivaX(posActX);
            ActInfoTextual();
        } else {
            System.out.println("Se trata de exceder el límite Derecho");
        }
    }//GEN-LAST:event_btnMapaDerechaActionPerformed

    private void btnActSimActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnActSimActionPerformed
        //INICIAR ALGORITMO POR RMI
        //gestorInter.iniHiloGenetico();
        gestorInter.iniHiloGenetico();
    }//GEN-LAST:event_btnActSimActionPerformed

    private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton2ActionPerformed

        if (validarCamposZonaActual()) {
            int posActX = (Integer.parseInt(txtZonaPosX.getText()) / 1000) * 1000;
            int posActY = (Integer.parseInt(txtZonaPosY.getText()) / 1000) * 1000;

            if ((posActX < ((nZonasLargo) * 1000)) && (posActY < ((nZonasAlto) * 1000))) {
                gestorGUI.setZonaActivaX(posActX);
                gestorGUI.setZonaActivaY(posActY);
                ActInfoTextual();
                txtZonaPosY.setText(null);
                txtZonaPosX.setText(null);
            } else {
                System.out.println("Se excede los límites: " + posActX + " " + posActY);
                txtZonaPosY.setText(null);
                txtZonaPosX.setText(null);
            }
        }

    }//GEN-LAST:event_jButton2ActionPerformed

    private void btnActVelPromActionPerformed(java.awt.event.ActionEvent evt){
        lblVelocidadProm.setText(""+gestorGUI.getVelocidadProm());
    }
    private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed
        String[] aux = null;
        (new pe.edu.pucp.dp1.lectura.controlador.MainLectura()).main(aux);
    }//GEN-LAST:event_jButton1ActionPerformed

    private void jMenuItem1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuItem1ActionPerformed
        // TODO add your handling code here:
//        frames.Reporte1 r1= new frames.Reporte1();
//        r1.setTitle("Zonas donde se aplica el algoritmo");
//        r1.setVisible(true);
    }//GEN-LAST:event_jMenuItem1ActionPerformed

    private void jMenuItem2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuItem2ActionPerformed
        // TODO add your handling code here:
//        frames.Reporte2 r2= new frames.Reporte2();
//        r2.setTitle("Ranking de las zonas más congestionadas de la ciudad");
//        r2.setVisible(true);
    }//GEN-LAST:event_jMenuItem2ActionPerformed

    private void jMenuItem3ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuItem3ActionPerformed
        // TODO add your handling code here:
        //frames.Reporte3 r3= new frames.Reporte3();
        //r3.setVisible(true);
//        frames.Reportes r = new frames.Reportes();
//        r.JavierMetodoPublico(evt);
        
    }//GEN-LAST:event_jMenuItem3ActionPerformed

    private void jMenuItem4ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuItem4ActionPerformed
        // TODO add your handling code here:
//        frames.Reporte4 r4= new frames.Reporte4();
//        r4.setTitle("Carga vehicular a lo largo del día");
//        r4.setVisible(true);
    }//GEN-LAST:event_jMenuItem4ActionPerformed

    public static void main(String args[]) {
        /* Set the Nimbus look and feel */
        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
        /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
         * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html 
         */
        try {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                if ("Nimbus".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        } catch (ClassNotFoundException ex) {
            java.util.logging.Logger.getLogger(Principal.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(Principal.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(Principal.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(Principal.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        //</editor-fold>

        /* Create and display the form */
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new Principal(false).setVisible(true);
            }
        });
    }

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton btnActSim;
    private javax.swing.JButton btnActVelProm;
    private javax.swing.JButton btnIniSim;
    private javax.swing.JButton btnMapaAbajo;
    private javax.swing.JButton btnMapaArriba;
    private javax.swing.JButton btnMapaDerecha;
    private javax.swing.JButton btnMapaIzquierda;
    private javax.swing.JButton jButton1;
    private javax.swing.JButton jButton2;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JMenuItem jMenuItem1;
    private javax.swing.JMenuItem jMenuItem2;
    private javax.swing.JMenuItem jMenuItem3;
    private javax.swing.JMenuItem jMenuItem4;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JLabel lblCoord00;
    private javax.swing.JLabel lblCoordText;
    private javax.swing.JLabel lblCoordValue;
    private javax.swing.JLabel lblErrorZonaActual;
    private javax.swing.JLabel lblVelocidadProm;
    private javax.swing.JLabel lblZonaPosX;
    private javax.swing.JLabel lblZonaPosY;
    private javax.swing.JMenu menuArchivo;
    private javax.swing.JMenuItem menuInter;
    private javax.swing.JMenuBar menuMain;
    private javax.swing.JMenu menuManten;
    private javax.swing.JMenu menuReportes;
    private javax.swing.JPanel pnlContainerMiniMapa;
    private javax.swing.JPanel pnlControles;
    private javax.swing.JPanel pnlDataActual;
    private javax.swing.JPanel pnlMapa;
    private javax.swing.JPanel pnlSimulacion;
    private javax.swing.JPanel pnlVelProm;
    private javax.swing.JTextField txtZonaPosX;
    private javax.swing.JTextField txtZonaPosY;
    // End of variables declaration//GEN-END:variables

    private void pruebaBD() {
        try {
            BaseDatos bd = new BaseDatos();
            if (bd.AutorizarAcceso("admin", "admin")) {
                jLabel2.setText("correcto");
            }
            //jLabel1.setText(BaseDatos.DiaCorrespondiente(5));
        } catch (Exception e) {
        }

    }

    public Boolean getUsuarioAdmin() {
        return usuarioAdmin;
    }

    public void setUsuarioAdmin(Boolean usuarioAdmin) {
        this.usuarioAdmin = usuarioAdmin;
    }

    public void ActInfoTextual() {
        //Establecer datos iniciales obtenidos por RMI
        lblZonaPosX.setText(String.valueOf(gestorGUI.getZonaActivaX()));
        lblZonaPosY.setText(String.valueOf(gestorGUI.getZonaActivaY()));
        lblCoord00.setText("(" + String.valueOf(gestorGUI.getZonaActivaX()) + "," + String.valueOf(gestorGUI.getZonaActivaY()) + ")");
        miniMapa.setPosX(gestorGUI.getZonaActivaX() / 1000);
        miniMapa.setPosY(gestorGUI.getZonaActivaY() / 1000);
        miniMapa.repaint();
    }

    public void ConfigurarMiniMapa() {

        miniMapa.setBackground(new Color(204, 255, 204));
        miniMapa.setSize(240, 160);
        miniMapa.setLocation(2, 2);

        miniMapa.addMouseMotionListener(new MouseMotionAdapter() {
            public void mouseMoved(MouseEvent e) {
                lblCoordValue.setText(e.getX() * 1000 + "," + (159 - e.getY()) * 1000);
            }
        });
        miniMapa.addMouseListener(new MouseAdapter() {
            public void mousePressed(MouseEvent me) {
                //txtZonaPosX.setText(String.valueOf(me.getX()*1000));
                //txtZonaPosY.setText(String.valueOf((159 - me.getY())*1000));
                gestorGUI.setZonaActivaX(me.getX() * 1000);
                gestorGUI.setZonaActivaY((159 - me.getY()) * 1000);
                miniMapa.setPosX(me.getX());
                miniMapa.setPosY(159 - me.getY());
                miniMapa.repaint();
                ActInfoTextual();
            }
        });

        miniMapa.validate();
    }

    public void ZonasPatronMiniMapa() {
        for (int i = 0; i < nZonasLargo; i++) {
            for (int j = 0; j < nZonasAlto; j++) {
                if (gestorInter.getMatrizZonaPatron()[i][j] == true) {
                    miniMapa.getZonasPatron()[i][j] = true;
                } else {
                    miniMapa.getZonasPatron()[i][j] = false;
                }
            }
        }
    }

    public boolean validarCamposZonaActual() {
        boolean auxReturn = true;
        if (!txtZonaPosX.getText().matches("\\d+") || !txtZonaPosY.getText().matches("\\d+")) {
            lblErrorZonaActual.setText("Ingrese solo números");
            auxReturn = false;
        } else {
            lblErrorZonaActual.setText("");
        }
        return auxReturn;
    }
}
